package com.jianzong.lingxuan.api.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jianzong.lingxuan.api.entity.*;
import com.jianzong.lingxuan.api.entity.vo.UserGame;
import com.jianzong.lingxuan.api.mapper.*;
import com.jianzong.lingxuan.api.service.GameService;
import com.jianzong.lingxuan.api.service.SectFriendApplicantService;
import com.jianzong.lingxuan.api.service.SectUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jianzong.lingxuan.base.Result;
import com.jianzong.lingxuan.common.RedisService;
import com.jianzong.lingxuan.enums.CaptchaEnum;
import com.jianzong.lingxuan.enums.SysInfo;
import com.jianzong.lingxuan.error.SysError;
import com.jianzong.lingxuan.util.PageUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;

import static com.jianzong.lingxuan.enums.CaptchaEnum.*;

/**
 * 宗门-用户表 服务实现类
 * @author lwl
 * @since 2021-07-20
 */
@Service
@Transactional
public class SectUserServiceImpl extends ServiceImpl<SectUserMapper, SectUser> implements SectUserService {

    public final SectUserMapper sectUserMapper;
    public final SectLoginMapper sectLoginMapper;
    public final RedisService redisService;
    public final SectFriendsMapper sectFriendsMapper;
    public final SectGongfaMapper sectGongfaMapper;
    public final SectCharacterMapper sectCharacterMapper;
    public final SectLevelMapper sectLevelMapper;
    public final SectEmailMapper sectEmailMapper;
    public final GameService gameService;
    public final SectFriendApplicantMapper sectFriendApplicantMapper;
    //引入验证码
    public final CaptchaService captchaService;

    public SectUserServiceImpl( SectUserMapper sectUserMapper,SectLoginMapper sectLoginMapper,RedisService redisService,
                                SectFriendsMapper sectFriendsMapper,SectGongfaMapper sectGongfaMapper,
                                SectCharacterMapper sectCharacterMapper,SectLevelMapper sectLevelMapper,
                                SectEmailMapper sectEmailMapper,GameService gameService,SectFriendApplicantMapper sectFriendApplicantMapper,
                                CaptchaService captchaService
                                ){
        this.sectUserMapper = sectUserMapper;
        this.sectLoginMapper = sectLoginMapper;
        this.redisService = redisService;
        this.sectFriendsMapper = sectFriendsMapper;
        this.sectGongfaMapper = sectGongfaMapper;
        this.sectCharacterMapper = sectCharacterMapper;
        this.sectLevelMapper = sectLevelMapper;
        this.sectEmailMapper = sectEmailMapper;
        this.gameService = gameService;
        this.sectFriendApplicantMapper = sectFriendApplicantMapper;
        this.captchaService = captchaService;
    }

    /**
     * @Description: 宗门app前台登录
     * @Parameter:[map]
     * @Return:com.jianzong.lingxuan.base.Result<?>
     * @Author:leiwenlong
     * @Date:2021/7/20
     **/
    @Override
    public Result<?> login(Map<String, String[]> map, CaptchaVO captchaVO) {

        //1.校验图形验证码
        //必传参数：captchaVO.captchaVerification
        ResponseModel response = captchaService.verification(captchaVO);
        int parseInt = Integer.parseInt(response.getRepCode());
/*
        if(!response.isSuccess()){
            if(ObjectUtil.isNull(CaptchaEnum.getByCode(parseInt))){
                return Result.error(NOT_ERROR.getMsg());
            }
            switch (Objects.requireNonNull(getByCode(parseInt))){
                case NOT_ERROR:
                    return Result.error(NOT_ERROR.getMsg());
                case SERVICE_ERROR:
                    return Result.error(SERVICE_ERROR.getMsg());
                case NOT_PARAMETER:
                    return Result.error(NOT_PARAMETER.getMsg());
                case MSG_ISVAILD:
                    return Result.error(MSG_ISVAILD.getMsg());
                case VERIFICATION_ERROR:
                    return Result.error(VERIFICATION_ERROR.getMsg());
                case MSG_ERROR:
                    return Result.error(MSG_ERROR.getMsg());
                case CHECK_PATH:
                    return Result.error(CHECK_PATH.getMsg());
                case REQ_OVERRUN:
                    return Result.error(REQ_OVERRUN.getMsg());
                case INVALID_REQUEST:
                    return Result.error(INVALID_REQUEST.getMsg());
                case INTERFACE_ERROR_MONY:
                    return Result.error(INTERFACE_ERROR_MONY.getMsg());
                case CHECK:
                    return Result.error(CHECK.getMsg());

            }
        }
*/

        //2.解析map内的参数
        String userName = map.get("userName")[0];
        String passWord = map.get("passWord")[0];

        if (ObjectUtil.isNull(userName) || ObjectUtil.isNull(passWord)) {
            return Result.error(SysInfo.LOGIN_CHECK2);
        }

        //2.处理解析数据，获取账户名和密码
        String md5ps = SecureUtil.md5(passWord);
        QueryWrapper<SectUser> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_name", userName).eq("pass_word", md5ps).eq("is_valid", 0).eq("state", 0);

        //3.调用mybatis查询接口 获取对应用户数据
        SectUser sectUser = sectUserMapper.selectOne(queryWrapper);

        if (ObjectUtil.isNull(sectUser)) {
            return Result.error(SysInfo.LOGIN_CHECK);
        }

        //4.再判断当前用户状态
        if (!sectUser.getIsValid().equals(0) && !sectUser.getState().equals(0)) {
            return Result.error(SysInfo.LOGIN_CHECK3);
        }

        //5.往登录记录表插入登录信息
        SectLogin sectLogin = new SectLogin();


        try {
            InetAddress ip4 = Inet4Address.getLocalHost();

            sectLogin.setUserId(sectUser.getId());
            sectLogin.setIpAddr(ip4.getHostAddress());
            sectLogin.setDevice("");
            sectLogin.setLoginTime(new Date());
            sectLoginMapper.insert(sectLogin);

        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        Map<String, Object> userResult = sectUserMapper.selectUserInfo(userName, md5ps);

        //登录token
        String token = IdUtil.simpleUUID();
        redisService.set(token,userResult);
        userResult.put("token", token);

        return Result.success(userResult);

    }

    /**
     *@Description:  宗门app前台注册
     *@Parameter:[map]
     *@Return:com.jianzong.lingxuan.base.Result<?>
     *@Author:leiwenlong
     *@Date:2021/7/20
     **/
    @Override
    public Result<?> register(Map<String, String[]> map) {

        //1.解析map内的参数
        String userName = map.get("userName")[0];
        String passWord = map.get("passWord")[0];
        //推荐人ID
        String pid = map.get("pid")[0];
        //昵称
        String nickName = map.get("nickName")[0];

        QueryWrapper<SectUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("nick_name",nickName).or().eq("user_name",userName)
                .eq("is_valid",0).eq("state",0);

        List<SectUser> sectUsers = sectUserMapper.selectList(queryWrapper);

        if(sectUsers.size()>0){
            return Result.error(SysInfo.NAME_EXISTS);
        }

        SectUser sectUser = new SectUser();
        //注册初始化数据
        sectUser.setUserName(userName);
        sectUser.setPid(Integer.valueOf(pid));
        sectUser.setNickName(nickName);
        sectUser.setLevelId(1);

        //关联登录数据
        sectUser.setLoginId(0);
        //关联仓库数据
        sectUser.setHouseId(0);
        //关联背包数据
        sectUser.setKnapsackId(0);
        //关联功法数据
        sectUser.setGongfaId(0);
        //关联宠物数据
        sectUser.setPetsId(0);
        //关联坐骑数据
        sectUser.setMountId(0);
        //关联朋友列表数据
        sectUser.setFriendsId(0);
        //关联任务数据
        sectUser.setTaskId(0);

        Integer characterId = sectCharacterMapper.insert(new SectCharacter());

        //关联人物数据
        sectUser.setCharacterId(characterId);

        //关联邮箱数据
        sectUser.setEmailId(0);

        //时间数据初始化
        sectUser.setCreateTime(new Date());
        sectUser.setUpdateTime(new Date());

        if(ObjectUtil.isNotNull(userName) && ObjectUtil.isNotNull(passWord)){
            String md5ps = SecureUtil.md5(passWord);
            sectUser.setPassWord(md5ps);

           //2.调用mybatis添加接口 添加对应用户数据
            sectUserMapper.insert(sectUser);

            return Result.success(SysInfo.REGISTER_INFO);
        }else{
            return Result.error(SysInfo.LOGIN_CHECK2);
        }
    }

    /**
    *@Description: 查看 【朋友列表】
    *@Parameter:[map]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/22
    **/
    @Override
    public Result<?> friendList(Map<String, String[]> map,String token) {
        //获取信息
        Object tokens = redisService.get(token);

        if(ObjectUtil.isNull(tokens) || ObjectUtil.isEmpty(tokens) ){
            return Result.error(SysError.TOKEN_REQUIRED);
        }

        Map<String, Object> objectMap = (Map<String, Object>) tokens;
        Object id = objectMap.get("id");


        String current = map.get("current")[0];
        String size = map.get("size")[0];

        Page<Map<String, Object>> page = new Page<Map<String, Object>>();
        page.setSize(Integer.parseInt(size));
        page.setCurrent(Integer.parseInt(current));

        //查询朋友列表 返回数据
        Page<Map<String, Object>>  friendList  = sectFriendsMapper.selectFriendsList(id.toString(), page);
        return Result.success(friendList);
    }

    /**
     *@Description: 查看 【功法列表】
     *@Parameter:[map]
     *@Return:com.jianzong.lingxuan.base.Result<?>
     *@Author:leiwenlong
     *@Date:2021/7/23
     **/
    @Override
    public Result<?> GongfaList(Map<String, String[]> map, String token) {

        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object id = checkToPage.getId();
        Page<Map<String, Object>> page = checkToPage.getPage();

        //查询朋友列表 返回数据
        page  = sectGongfaMapper.selectGoogfaList(id.toString(), page);
        return Result.success(page);
    }

    /**
    *@Description: 【查看用户任务列表】
    *@Parameter:[map]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/26
    **/
    @Override
    public Result<?> queryTaskList(Map<String, String[]> map, String token) {

        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object id = checkToPage.getId();
        Page<Map<String, Object>> page = checkToPage.getPage();

        //查询任务列表 返回数据
        page = sectUserMapper.queryTaskList(id.toString(),page);
        return Result.success(page);
    }

    /**
    *@Description: 【查看用户宠物列表】
    *@Parameter:[map, token]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/26
    **/
    @Override
    public Result<?> queryUserPetsList(Map<String, String[]> map, String token) {

        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object id = checkToPage.getId();
        Page<Map<String, Object>> page = checkToPage.getPage();

        //查询宠物列表 返回数据
        page = sectUserMapper.queryUserPetsList(id.toString(),page);
        return Result.success(page);
    }

    /**
    *@Description:  【查看用户宠物技能列表】
    *@Parameter:[map, token]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/26
    **/
    @Override
    public Result<?> queryUserPetsSkillList(Map<String, String[]> map, String token) {

        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object userPetsId = checkToPage.getUserPetsId();
        Page<Map<String, Object>> page = checkToPage.getPage();

        //查询宠物列表 返回数据
        page = sectUserMapper.queryUserPetsSkillList(userPetsId.toString(),page);
        return Result.success(page);
    }


    /**
     *@Description:  【查看用户骑宠列表】
     *@Parameter:[map, token]
     *@Return:com.jianzong.lingxuan.base.Result<?>
     *@Author:leiwenlong
     *@Date:2021/7/27
     **/
    @Override
    public Result<?> queryUserMountList(Map<String, String[]> map, String token) {
        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object id = checkToPage.getId();
        Page<Map<String, Object>> page = checkToPage.getPage();

        //查询宠物列表 返回数据
        page = sectUserMapper.queryUserMountList(id.toString(),page);
        return Result.success(page);
    }

    /**
     *@Description:  【查看用户骑宠技能列表】
     *@Parameter:[map, token]
     *@Return:com.jianzong.lingxuan.base.Result<?>
     *@Author:leiwenlong
     *@Date:2021/7/27
     **/
    @Override
    public Result<?> queryUserMountSKillList(Map<String, String[]> map, String token) {
        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object userMountId = checkToPage.getUserMountId();
        Page<Map<String, Object>> page = checkToPage.getPage();

        //查询宠物列表 返回数据
        page = sectUserMapper.queryUserMountSKillList(userMountId.toString(),page);
        return Result.success(page);
    }

    /**
    *@Description:  【查看用户邮箱列表】
    *@Parameter:[map, token]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/27
    **/
    @Override
    public Result<?> getEmailInfo(Map<String, String[]> map, String token) {
        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object id = checkToPage.getId();

        //查询邮箱列表 返回数据
        QueryWrapper<SectEmail> emailQueryWrapper = new QueryWrapper<>();
        Page<SectEmail> emailPage = new Page<>();

        emailQueryWrapper.eq("user_id",id).eq("is_valid",0);

        Page<SectEmail> selectPage = sectEmailMapper.selectPage(emailPage, emailQueryWrapper);

        List<SectEmail> records = selectPage.getRecords();
        List<SectEmail> newRecords = new ArrayList<>();

        if(records.size()>0){
            for (SectEmail sectEmail: records) {
                SectUser sectUser = sectUserMapper.selectById(sectEmail.getSendUserId());
                sectEmail.setSendNickName(sectUser.getNickName());
                newRecords.add(sectEmail);
            }

            selectPage.setRecords(newRecords);
        }


        return Result.success(selectPage);
    }

    /**
    *@Description:  战斗系统【用户PK用户】
    *@Parameter:[map, token]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/28
    **/
    @Override
    public Result<?> simulationPK(Map<String, String[]> map, String token) {

        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        //获取用户ID
        Object userId = checkToPage.getId();
        Object twoUserId =checkToPage.getTwoUserId();

        UserGame userGame =  new UserGame(sectUserMapper.selectById(userId.toString()));
        UserGame userGameTwo =  new UserGame(sectUserMapper.selectById(twoUserId.toString()));
        Map<String, Object> game = gameService.game(userGame, userGameTwo);

        if(ObjectUtil.isNull(game.get("pkNum"))){
            return Result.error(SysInfo.PK_CHECK_INFO);
        }

        return Result.success(game);
    }

    /**
    *@Description: 用户【添加好友】
    *@Parameter:[map, token]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/29
    **/
    @Override
    public Result<?> addFriend(Map<String, String[]> map, String token) {

        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        //获取用户ID
        Object userId = checkToPage.getId();
        //获取查看朋友名称
        Object friendName =checkToPage.getFriendName();
        //获取对应关系
        Object relationship = checkToPage.getRelationship();
        //获取申请内容
        Object applicantContext = checkToPage.getApplicantContext();

        String isNot = sectFriendsMapper.selectFriendIsNot(userId.toString(), friendName.toString());

        if(ObjectUtil.isNotNull(isNot)){
            return Result.error(SysInfo.FRIEND_CHECK);
        }

        //根据名称查询此用户
        // 并添加值用户朋友关联表
        QueryWrapper<SectUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("nick_name",friendName);
        SectUser sectUser = sectUserMapper.selectOne(queryWrapper);

        if(ObjectUtil.isNull(sectUser)){
            return Result.error(SysInfo.FRIEND_NOTFOUND);
        }

        //生成朋友添加申请表 待对方同意加好友
        SectFriendApplicant friendApplicant = new SectFriendApplicant();

        //关联关系
        friendApplicant.setApplicantId(Integer.parseInt(userId.toString()));
        friendApplicant.setUserId(sectUser.getId());
        friendApplicant.setCreateTime(new Date());
        friendApplicant.setApplicantContext(applicantContext.toString());
        friendApplicant.setRelationship(relationship.toString());

        sectFriendApplicantMapper.insert(friendApplicant);

        return Result.success(SysInfo.FRIENDAPPLICANT_SUCCESS);

    }

    /**
    *@Description: 前台【用户朋友验证信息列表】
    *@Parameter:[map, token]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/29
    **/
    @Override
    public Result<?> queryFriendApplicantList(Map<String, String[]> map, String token) {
        PageUtil.CheckToPage checkToPage = new PageUtil.CheckToPage(map, token,redisService).invoke();
        if (checkToPage.is()) { return Result.error(SysError.TOKEN_REQUIRED);}

        Object id = checkToPage.getId();

        //查询邮箱列表 返回数据
        QueryWrapper<SectFriendApplicant> queryWrapper = new QueryWrapper<>();
        Page<SectFriendApplicant> sectFriendApplicantPage = new Page<>();

        queryWrapper.eq("user_id",id);

        Page<SectFriendApplicant> selectPage = sectFriendApplicantMapper.selectPage(sectFriendApplicantPage, queryWrapper);

        List<SectFriendApplicant> records = selectPage.getRecords();
        List<SectFriendApplicant> newRecords = new ArrayList<>();

        if(records.size()>0){
            for (SectFriendApplicant sectFriendApplicant: records) {
                SectUser sectUser = sectUserMapper.selectById(sectFriendApplicant.getApplicantId());
                SectLevel sectLevel = sectLevelMapper.selectById(sectUser.getLevelId());
                sectFriendApplicant.setNickName(sectUser.getNickName());
                sectFriendApplicant.setLevelName(sectLevel.getLevelName());
                newRecords.add(sectFriendApplicant);
            }

            selectPage.setRecords(newRecords);
        }


        return Result.success(selectPage);
    }

    /**
    *@Description: 后台查看【用户列表】
    *@Parameter:[map]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/23
    **/
    @Override
    public Result<?> userList(Map<String, String[]> map) {

        String current = map.get("current")[0];
        String size = map.get("size")[0];
        String nickName = map.get("nickName")[0];
        String level = map.get("level")[0];

        Page<SectUser> page = new Page<SectUser>();
        page.setSize(Integer.parseInt(size));
        page.setCurrent(Integer.parseInt(current));

        QueryWrapper<SectUser> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.like("nick_name","%"+nickName+"%");
        if(!level.equals("")){
            userQueryWrapper.eq("level_id",level);
        }


        Page<SectUser> sectUserPage = sectUserMapper.selectPage(page, userQueryWrapper);

        List<SectUser> records = sectUserPage.getRecords();
        List<SectUser> newRecords = new ArrayList<>();
        for(SectUser sectUser: records){
            SectLevel sectLevel = sectLevelMapper.selectById(sectUser.getLevelId());
            sectUser.setLevelName(sectLevel.getLevelName());
            sectUser.setLevelIcon(sectLevel.getLevelIcon());
            newRecords.add(sectUser);
        }

        sectUserPage.setRecords(newRecords);
        return Result.success(sectUserPage);
    }

    /**
    *@Description:  后台查看【用户信息】
    *@Parameter:[map, token]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/23
    **/
    @Override
    public Result<?> getUserInfo(Map<String, String[]> map, String token) {
        String id = map.get("id")[0];
        Map<String, Object> userResult = sectUserMapper.selectUserInfoByAdmin(id);
        return Result.success(userResult);
    }

    /**
    *@Description:  后台查看【ID免登陆】
    *@Parameter:[map]
    *@Return:com.jianzong.lingxuan.base.Result<?>
    *@Author:leiwenlong
    *@Date:2021/7/25
    **/
    @Override
    public Result<?> loginById(Map<String, String[]> map) {
        //1.解析map内的参数
        String id = map.get("id")[0];


        if (ObjectUtil.isNull(id) ) {
            return Result.error(SysInfo.LOGIN_CHECK2);
        }

        //2.处理解析数据，获取账户名和密码
        QueryWrapper<SectUser> queryWrapper = new QueryWrapper();
        queryWrapper.eq("id", id).eq("is_valid", 0).eq("state", 0);

        //3.调用mybatis查询接口 获取对应用户数据
        SectUser sectUser = sectUserMapper.selectOne(queryWrapper);

        if (ObjectUtil.isNull(sectUser)) {
            return Result.error(SysInfo.LOGIN_CHECK);
        }

        //4.再判断当前用户状态
        if (!sectUser.getIsValid().equals(0) && !sectUser.getState().equals(0)) {
            return Result.error(SysInfo.LOGIN_CHECK3);
        }


        Map<String, Object> userResult = sectUserMapper.selectUserInfo(sectUser.getUserName(), sectUser.getPassWord());

        //登录token
        String token = IdUtil.simpleUUID();
        redisService.set(token,userResult);
        userResult.put("token", token);

        return Result.success(userResult);
    }


    public Result ceshi(){
        //添加朋友信息
        SectFriends sectFriends = new SectFriends();

        //关联信息
        sectFriends.setRelationship("");
        sectFriends.setFriendId(sectFriends.getId());
        sectFriends.setUserId(Integer.parseInt(String.valueOf("")));

        sectFriendsMapper.insert(sectFriends);

        return Result.success(SysInfo.ADD_SUCCESS);
    }

}